{% macro title_or_last(component, offset=2) %}
    {% set length = component.components | length %}
    {% set name = component.components | last %}
    {{ component.title | default(value=name) }}
{% endmacro title_or_last %}

{% macro format_date(date) %}
    {% set date_format = config.extra.date_format | default(value="%a %b %e, %Y") %}
    {{ date | date(format=date_format) }}
{% endmacro format_date %}

{% macro section_menu(path) %}
    <p>
        {% set index = get_section(path=path) %}
        {% for current in index.subsections %}
            {% set current = get_section(path=current) %}
            <a href="{{ current.permalink }}">{{ macros::title_or_last(component=current) }}</a>
        {% if loop.last == false %} &#183; {% endif %}
        {% endfor %}
    </p>
{% endmacro section_menu %}

{% macro bottom_menu() %}
    <div class="section bottom-menu">
        <hr/>
        <p>
            {% if config.extra.sam_menu and config.extra.sam_bottom_menu %}
                {% for link in config.extra.sam_menu %}
                    <a href="{{ link.link }}">{{ link.text }}</a>
                    &#183;
                {% endfor %}
            {% elif config.extra.sam_bottom_menu %}
                {% set index = get_section(path="_index.md") %}
                {% for current in index.subsections %}
                    {% set current = get_section(path=current) %}
                    <a href="{{ current.permalink }}">{{ macros::title_or_last(component=current) }}</a>
                    &#183;
                {% endfor %}
            {% endif %}
            <a href="{{ config.base_url }}">
                {{ config.extra.home | default(value="home") }}
            </a>
        </p>
    </div>
{% endmacro bottom_menu %}

{% macro footer() %}
    {% if config.extra.sam_footer %}
        <div class="section footer">
            {{ config.extra.sam_footer.text | safe }}
        </div>
    {% endif %}
{% endmacro footer %}
